﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.baseBLL;
using dhDataAcess.orderLinqDAL;
using dhDataAcess.dataAcess.orderDataSetTableAdapters;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.orderDAL;

namespace dhSystemBLL.orderData
{
  public   class pbomMarkBLL
    {

        private pbomMarkTableAdapter _pbomMarkAdapter = null;
        private pbomMarkTableAdapter pbomMarkAdapter
        {
            get
            {
                if (_pbomMarkAdapter == null) _pbomMarkAdapter = new pbomMarkTableAdapter();
                return _pbomMarkAdapter;
            }
        }
        /// <summary>
        /// 查询产品BOM技术参数表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public orderDataSet.pbomMarkDataTable getpbomMarkAll()
        {
            try
            {
                return pbomMarkAdapter.GetDatapbomMarkALL();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 根据产品名称名称查询产品BOM技术参数表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public orderDataSet.pbomMarkDataTable getpbomMarkAllBypname(string pname)
        {
            try
            {
                return pbomMarkAdapter.GetDatapbomMarkBypname (pname);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 根据产品名称名称查询产品BOM技术参数表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public orderDataSet.pbomMarkDataTable getpbomMarkAllBypnamelike(string pname)
        {
            try
            {
                return pbomMarkAdapter.GetDatalikeBypname (pname);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
        /// <summary>
        /// 插入产品BOM技术参数表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public int pbomMarkInsert(pbomMarkModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pbomMarkDAL pbomMark = new pbomMarkDAL(tn,conn );
                pbomMark.pbomMarkInsert(row);
                tn.Commit();
                return i;

            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
                
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新产品BOM技术参数表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public int pbomMarkUpdate(pbomMarkModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pbomMarkDAL pbomMark = new pbomMarkDAL(tn, conn);
                pbomMark.pbomMarkUpdate(row);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
               
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除一行产品BOM技术参数表
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public int pbomMarkDel(string matNum)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                pbomMarkDAL pbomMark = new pbomMarkDAL(tn, conn);
                pbomMark.pbomMarkDel (matNum );
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
                
            }
            finally
            {
                conn.Close();
            }
        }
    }
}
